package cn.cvs.controller;

import cn.cvs.entity.User;
import cn.cvs.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class LoginController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public String login(HttpServletRequest request, String username, String password){
        User user = userService.login(username, password);
        if (user == null){
            // 登录失败
            return "index";
        }

        request.getSession().setAttribute("loginUser",user);

        return "redirect:list";
    }
}
